<template>
	<view>
		<view v-for="(i, index) in data" :key="index">
			<view v-if="i.id==inde">
				<uni-section title="标题" type="line">
					<uni-card>
						<text class="title">{{i.title}}</text>
					</uni-card>
				</uni-section>
				<uni-section title="内容" type="line">
				<uni-card>
					<text class="uni-body">{{i.memo}}</text>
				</uni-card>
				</uni-section>
				<uni-section title="图片" type="line">
				<view v-if="i.uri!=null">
					<view v-for="(i, index) in i.uri" :key="index">
						<image :src="'http://xg.kystu.cn:8085'+i"></image>
					</view>
				</view>
				</uni-section>
				<uni-section title="其他" type="line">
					<view style="float: right;">
						<uni-icons class="footer-box right" type="hand-up-filled" size="30" v-show="showlike" @click.stop="good(i.id)"></uni-icons>
						<uni-icons class="footer-box right" type="hand-up" size="30" v-show="!showlike" @click.stop="good(i.id)"></uni-icons>
					</view>
					<text class="title" style="height: 30px;">制作者：{{i.username}}</text>
				</uni-section>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				data: [],
				inde: '',
				showlike:false,
				searchListUrl: 'http://xg.kystu.cn:8085/system/projectcontent_cj/list?classone=竞赛&state=1',
				getLikeUrl:'http://xg.kystu.cn:8085/system/ok/state'
			}
		},
		methods: {
			getLikeCode(){
				var _this=this;
				_this.getLikeUrl='http://xg.kystu.cn:8085/system/ok/state?tableId='+_this.inde+'&tableType=record'
				uni.request({
					url:_this.getLikeUrl,
					method: "GET",
					header: {
						'Authorization': "Bearer " + _this.token
					},
					success: (res) => {
						if(res.data.code==200){
							_this.showlike=true
						}
						if(res.data.code==0){
							_this.showlike=false
						}
					}
				});
			},
			good(id) {
				var _this = this;
				console.log("点赞")
				uni.request({
					url: 'http://xg.kystu.cn:8085/system/ok/click',
					method: 'POST',
					header: {
						'Authorization': "Bearer " + _this.token
					},
					data: {
						"tableId": id,
						"tableType": "record"
					},
					success: (res) => {
						_this.showlike=!_this.showlike;
					}
				})

			},
			onLoad(option) {
				console.log('上一个页面传递过来的参数', option)
				console.log('id', option.index)
				this.inde = option.index
				// 接下来就是你需要该id做些什么，比如通过id查询到该详情等
			},
			onShow() {
				var _this = this;
				uni.getStorage({
					key: 'App-Token',
					success(res) {
						_this.token = res.data;
						_this.getLikeCode();
						uni.request({
							url: _this.searchListUrl,
							method: 'GET',
							header: {
								'Authorization': "Bearer " + _this.token
							},
							success: (res) => {
								if (res.data.code == 200) {
									_this.data = []
									for (var i = 0; i < res.data.total; i++) {
										_this.data.push({
											'title': '',
											'memo': '',
											'uri': '',
											'updatetime': '',
											'username': '',
											'id': '',
											'oknum':''
										})
										console.log(res.data.rows[i].title)
										_this.data[i].title = res.data.rows[i].title;
										_this.data[i].memo = res.data.rows[i].mycontent;
										var m = res.data.rows[i].upimage.split(",");
										_this.data[i].uri = m;
										// 'http://xg.kystu.cn:8085' 
										_this.data[i].updatetime = res.data.rows[i].updatetime;
										_this.data[i].username = res.data.rows[i].username;
										_this.data[i].oknum = res.data.rows[i].oknum;
										_this.data[i].id = res.data.rows[i].id;
									}
								}

							}
						})
					}
				})
			}
		}
	}
</script>

<style>
	.title {
		text-align: center;
		color: black;
		display: block;
	}

	.footer-box .left {
		float: right;
		text-align: right;
		width: 100%;
	}

	.footer-box .content {
		float: right;
		text-align: right;
		width: 100%;
	}

	.footer-box .right {
		float: right;
		text-align: right;
		width: 100%;
	}
</style>
